set inten on
STORE 0 TO CNT,CR
play=savescreen(0,0,24,79)
sele 1
set exclu off
use &dr&f1 inde &dr&f11
seek ALLTRIM(kunci)

if .not. eof()
   DO WHILE left(&NAMEMAC,len(kunci))=alltrim(kunci)
*      CNT=CNT+1
      IF TYPSPEC='1'
         IF (SUBS(DRUG_CODE,2,1)='0' .OR. SUBS(DRUG_CODE,2,1)='1') .and. st_act_buy<st_max
            CNT=CNT+1
         ENDIF
      ELSE
         IF SUBS(&CODEMAC,2,1)=TYPSPEC .and. st_act_buy<st_max
            cnt=cnt+1
         ENDIF
      ENDIF
      skip
   ENDDO
   IF CNT=0
      RETURN
   ENDIF
   DECLARE FILD[CNT]
   DECLARE drcod[CNT]
   DECLARE CNAM[CNT]
   seek ALLTRIM(kunci)
   if .not. eof()
      DO WHILE left(&NAMEMAC,len(kunci))=alltrim(kunci)
         IF TYPSPEC='1'
            IF (SUBS(DRUG_CODE,2,1)='0' .OR. SUBS(DRUG_CODE,2,1)='1') .and. st_act_buy<st_max
               CR=CR+1
               nm=alltrim(&NAMEMAC)+' '+alltrim(&TYPEMAC)+' '+alltrim(&QANTMAC)+' '+alltrim(&UNITMAC)
               FILD[CR]=subs(NM,1,45)+space(45-len(nm))+'  '+&CODEMAC
               drcod[CR]=&CODEMAC
               CNAM[CR]=&NAMEMAC
            ENDIF
         ELSE
            IF SUBS(&CODEMAC,2,1)=TYPSPEC .and. st_act_buy<st_max
               CR=CR+1
               nm=alltrim(&NAMEMAC)+' '+alltrim(&TYPEMAC)+' '+alltrim(&QANTMAC)+' '+alltrim(&UNITMAC)
               FILD[CR]=subs(NM,1,45)+space(45-len(nm))+'  '+&CODEMAC
               drcod[CR]=&CODEMAC
               CNAM[CR]=&NAMEMAC
            ENDIF
         ENDIF
         SKIP
      ENDDO
   endif
   set colo to w/b
   inkey()
   set colo to w+/rb,gr+/r
   @ 15,3 clea to 22,75
   @ 15,3 to 22,75 double
   pilih=achoice(16,5,21,73,FILD)
   IF LASTKEY()=13
      DARF=FILD[PILIH]
      kode=drcod[PILIH]
      name=CNAM[PILIH]
   else
      restscreen(0,0,24,79,play)
*      close database
*      close index
*      set color to n/bg/w+/n
      return
   ENDIF
else
   name=space(32)
endif
return